<?php
/**
 * @version 1.0
 * @author jonathan <jo.link.noir@gmail.com>
 * @date 13-03-2010
 */
class U1_Display_Move_Arrived
{
	/**
	 * Méthode à déclencher quand l'armé est arrivé à destination
	 * @param SW_Units $army
	 * @param SW_Move_Message $message = null : nom de la fonction
	 */
	public function arrive(SW_Units $army, SW_Move $move)
	{
		$move = $group->getMove();
		$planetStart = U1_Planet::factoryContainsPlanetId($move->getStartPoint());
		$planetEnd = U1_Planet::factoryContainsPlanetId($move->getEndPoint());

		echo $move->orderName.'['.$move->id.'] (p'.$move->player_sends.' -> p'.$move->player_target.') : '.self::textTargetPlanet($planetStart, $move->getStartPoint()).' -> '.self::textTargetPlanet($planetEnd, $move->getEndPoint()).' ('.$move->getTime().")\n";
		self::displayArmy($group->getUnits());
		if ($move instanceof U1_Move_Transport)
		{
			echo "\n\t -Transport :";
			if ($removable = $move->getRemovable('U1_Removable_Resource'))
			{
				$messR = '';
				foreach ($removable->getQuantities() as $k => $q)
					$messR .= "\n\t\t$k = $q";
				echo "\n\t".'Dépose des ressources'.$messR."\n";
			}

			if ($move->orderName === 'base')
			{
				$messR = '';
				foreach ($group->getUnits() as $g => $q)
					$messR .= "\n\t\t$g = ".$q->getCount();
				echo "\n\t".'Dépose des vaisseaux'.$messR."\n";
			}
		}
		echo "\n";
	}

	static protected function textTargetPlanet(SW_Planet $planet = null, $idPlanet)
	{
		return ($planet && $planet->exists($idPlanet))
			? implode(':', $planet->get($idPlanet)->getTarget())
			: 'Planète n°'.$idPlanet;
	}

	static public function displayArmy(SW_Units $army)
	{
		foreach ($army as $unity)
			echo "\t".$unity->getId().' : '.$unity->getCount()."\n";
	}
}